<!--
试题管理增加
 add by yyp 2019-06-04
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="TestQuestion" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:submitBefore="submitBefore")
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item.short(label="创建人名" prop="userName" v-bind:label-width="labelWidth" v-bind:rules="rules.userName")
        el-select(v-model="formModel.userId" placeholder="请选择" @change="getUid")
          el-option(v-for="item in options" v-bind:key="item.id" v-bind:label="item.name" v-bind:value="item.id")
      el-form-item.short(label="题库类别" prop="bankCategoryType"  v-bind:label-width="labelWidth" v-bind:rules="rules.bankCategoryType" )
        kalix-select(v-model="formModel.bankCategoryType"  v-bind:requestUrl="bankCategoryTypeUrl" id="name" appName="banktypename" placeholder="请选择题库类别" style="width:80%")
      el-form-item.short(label="题目类型" prop="subjectType"  v-bind:label-width="labelWidth" v-bind:rules="rules.subjectType" )
        kalix-select(v-model="formModel.subjectType"  v-bind:requestUrl="subjectTypes" v-on:input="change($event)" id="name" appName="subname" placeholder="请选择题目类型" style="width:80%")
      el-form-item.short(label="试题难度" prop="difficulty" v-bind:label-width="labelWidth" v-bind:rules="rules.difficulty")
        el-select(v-model="formModel.difficulty" placeholder="请选择" @change="aaa")
          el-option(v-for="item in level" v-bind:key="item.value" v-bind:label="item.label" v-bind:value="item.value")
      el-form-item(label="题目" prop="exerciseProblem" v-bind:label-width="labelWidth" v-bind:rules="rules.exerciseProblem")
        el-input(v-model="formModel.exerciseProblem" style="width:80%"  type="textarea")
      el-form-item(v-if="daa" label="回答" prop="exerciseAnswer" v-bind:label-width="labelWidth" v-bind:rules="rules.exerciseAnswer")
        el-input(v-model="formModel.exerciseAnswer" style="width:80%"  type="textarea")
      el-form-item(v-if="xxa" label="选项A" prop="optionA" v-bind:label-width="labelWidth" v-bind:rules="rules.optionA")
        el-input(v-model="formModel.optionA" style="width:80%"  )
      el-form-item(v-if="xxa" label="选项B" prop="optionB" v-bind:label-width="labelWidth" v-bind:rules="rules.optionB")
        el-input(v-model="formModel.optionB" style="width:80%"  )
      el-form-item(v-if="xxa" label="选项C" prop="optionC" v-bind:label-width="labelWidth" v-bind:rules="rules.optionC")
        el-input(v-model="formModel.optionC" style="width:80%"  )
      el-form-item(v-if="xxa" label="选项D" prop="optionD" v-bind:label-width="labelWidth" v-bind:rules="rules.optionD")
        el-input(v-model="formModel.optionD" style="width:80%"  )
      el-form-item.short(label="试题图片" prop="imgUrl" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="img"  :fileList="fileList" tipText="只能上传jpg/png文件")

</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {TestQuestionURL, BankCategoryURL, SubjectTypeURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  export default {
    name: 'testquestionAdd',
    components: {KalixSelect, KalixClansmanUpload},
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        action: baseURL + '/camel/rest/upload',
        rules: {
          name: [{required: true, message: '请输入名称', trigger: 'blur'}]
        },
        targetURL: TestQuestionURL,
        subjectTypes: SubjectTypeURL,
        bankCategoryTypeUrl: BankCategoryURL,
        labelWidth: '110px',
        options: [],
        filePathArr: [],
        fileList: [],
        daa: true,
        xxa: false,
        level: [{
          value: '难',
          label: '难'
        }, {
          value: '中',
          label: '中'
        }, {
          value: '易',
          label: '易'
        }],
        value: ''
      }
    },
    mounted() {
      this.getUname()
    },
    methods: {
      change(item) {
        if (item === '单选题' || item === '多选题') {
          this.daa = false
          this.xxa = true
        } else {
          this.daa = true
          this.xxa = false
        }
      },
      getFilePath(filePath, fileName) {
        this.filePathArr.push(filePath)
      },
      submitBefore(baseDialog, callBack) {
        let filePath = ''
        if (this.filePathArr.length > 0) {
          this.filePathArr.forEach(e => {
            filePath += e + ','
          })
          filePath = filePath.substr(0, filePath.length - 1)
        }
        console.log('filePath==========', filePath)
        baseDialog.formModel.imgUrl = filePath
        callBack()
      },
      aaa(val) {
        console.log('aaaaaaaaa', this.formModel.value)
      },
      getUname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          console.log('res========', res.data)
          this.options = res.data.data
        })
      },
      getUid(val) {
        let obj = {}
        obj = this.options.find((item) => {
          return item.id === val
        })
        this.formModel.userName = obj.name
        console.log('bbbbbbbbbbbbbbbbbbbbbb', this.formModel.userName)
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 70%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
    .none
      display none
</style>
